# include <stdio.h>
int main()
{
	int m = 0;
	int n = 0;
	scanf_s("%d %d", &m, &n);
	int t = 0;
	while (t = m % n)
	{
		m = n;
		n = t;
		}
	printf("%d", n);
	return 0;
}